package ca.ubc.icapture.genapha.forms;

import icapture.SQLMgr;
import icapture.beans.DB.CohortPopulation;
import java.util.ArrayList;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * User: btripp
 * Date: Sep 13, 2006
 * Time: 9:39:23 AM
 * To change this template use File | Settings | File Templates.
 */
public class FbatBinaryForm extends AnalysisFilesForm
{

    private ArrayList<CohortPopulation> subCohorts;
    private String[] selectedCohortSubPopulation;
    private boolean zeroIncomplete = false;
    private boolean zeroControls = false;
    private String format;
    private boolean filePerGene = false;

    public FbatBinaryForm()
    {
        super();
        setPhenotypes(SQLMgr.getPhenotypes(1));
        subCohorts = SQLMgr.getCohortPopulations();
        for (CohortPopulation subCohort : subCohorts)
        {
            subCohort.setPopulationName(subCohort.getCohort().getName() + "-" + subCohort.getPopulationName());
        }
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
    {
        ActionErrors errors = new ActionErrors();
        //todo check that phenotype matches with cohort
//       if(selectedPhenotype.length()==0)
//            errors.add("selectedPhenotype",new ActionMessage("error.entry.required"));
//       if(selectedCohort.length==0)// == null || (selectedCohorts[0].toString().equals(" ") && selectedCohorts.length==1))
//            errors.add("selectedCohort",new ActionMessage("error.entry.required"));
//
//        if(selectedGenes != null && selectedGenes.length ==0)// == null || (selectedCohorts[0].toString().equals(" ") && selectedCohorts.length==1))
//            errors.add("selectedGenes",new ActionMessage("error.entry.required"));
//
//        if(selectedPhenotype.length()>0 && selectedCohort.length>0){
//            //make sur there are phentypes for this cohort
//            for(int i=0;i<selectedCohort.length;i++){
//                if(SQLMgr.getPhenotypeUsage(Integer.parseInt(selectedPhenotype), Integer.parseInt(selectedCohort[i])) < 1 ){
//                    errors.add("selectedPhenotype",new ActionMessage("error.entry.invalid.phenotype"));
//                    break;
//                }
//            }
//        }
//        if(email.length()==0)
//            errors.add("email",new ActionMessage("error.entry.required"));
//        else if(!email.contains("@"))
//            errors.add("email",new ActionMessage("error.entry.invalid.email"));

        return errors;
    }

    /**
     * @return the subCohorts
     */
    public ArrayList<CohortPopulation> getSubCohorts()
    {
        return subCohorts;
    }

    /**
     * @param subCohorts the subCohorts to set
     */
    public void setSubCohorts(ArrayList<CohortPopulation> subCohorts)
    {
        this.subCohorts = subCohorts;
    }

    /**
     * @return the selectedCohortSubPopulation
     */
    public String[] getSelectedCohortSubPopulation()
    {
        return selectedCohortSubPopulation;
    }

    /**
     * @param selectedCohortSubPopulation the selectedCohortSubPopulation to set
     */
    public void setSelectedCohortSubPopulation(String[] selectedCohortSubPopulation)
    {
        this.selectedCohortSubPopulation = selectedCohortSubPopulation;
    }

    /**
     * @return the zeroIncomplete
     */
    public boolean isZeroIncomplete()
    {
        return zeroIncomplete;
    }

    /**
     * @param zeroIncomplete the zeroIncomplete to set
     */
    public void setZeroIncomplete(boolean zeroIncomplete)
    {
        this.zeroIncomplete = zeroIncomplete;
    }

    /**
     * @return the zeroControls
     */
    public boolean isZeroControls()
    {
        return zeroControls;
    }

    /**
     * @param zeroControls the zeroControls to set
     */
    public void setZeroControls(boolean zeroControls)
    {
        this.zeroControls = zeroControls;
    }

    /**
     * @return the format
     */
    public String getFormat()
    {
        return format;
    }

    /**
     * @param format the format to set
     */
    public void setFormat(String format)
    {
        this.format = format;
    }

    /**
     * @return the filePerGene
     */
    public boolean isFilePerGene()
    {
        return filePerGene;
    }

    /**
     * @param filePerGene the filePerGene to set
     */
    public void setFilePerGene(boolean filePerGene)
    {
        this.filePerGene = filePerGene;
    }
}
